home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: 12 Apr 1996 07:44:02 -0500
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4klj6i$nka@solutions.solon.com>
- References: <316112A2.7D37@public.sta.net.cn> <4kgu7g$n9a@solutions.solon.com> <4kjc9n$f7j@samba.rahul.net> <316E1037.41C67EA6@scn.de>
- Reply-To: seebs@solon.com
- NNTP-Posting-Host: solutions.solon.com
-
- In article <316E1037.41C67EA6@scn.de>,
- Gerolf Wendland <wendland%hpp015%hpp001.mch2.scn.de@scn.de> wrote:
- >Whoever started this, he wrote:
-
- >> >>: >> for (i=0; i<16; i++)
- >> >>: >> prom[i] = prom[i+i];
-
- >> >>: HUH? the code as written has a clear effect, which is to shove all of
- >> >>: the elements of an array over one. It certainly is an optimizer bug.
- ^^^^^^^^^^^^^^
- >Really?
-
- Well, it doesn't shove them over one. But, if you notice, the 2nd subscript
- is *different* from the first. The effect of this would presumably be to
- put every other value in the first half of the locations.
-
- >Richard Krehbiel:
- >>In fact, I wrote exactly this loop once whose purpose was to initialize the
- >>parity bits in memory, but be non-destructive in case it was just a
- >>restart and not a power-on.
-
- [By which, as I recall, he was talking about a loop with foo[i] = foo[i];]
-
- >This seems to indicate that prom[i] are assigned a values that are never used.
- >Maybe the optimizer has seen this. It should have issued a warning, which (the
- >issueing) may have been prevented by not prom being the variable but by the
- >somewhat anonymous locations prom[i] being the variables in question. The
- >optimizer would have been even better if it had seen the fact that the loop
- >is superflouos and had removed it as well.
-
- >The volatile keyword is surely a good way to circumvent this problem.
-
- It may work in this case, but it certainly shouldn't, if the values are ever
- used. If they aren't ever used, there's no way to tell that the code isn't
- running "correctly", so we assume they're used.
-
- It is almost never correct for a compiler to optimize out an assignment
- within a loop. Assuming that the program can tell in some way whether or
- not the assignments happened, it's an optimizer bug.
-
- (If the program can't tell, of course, then by the as-if rule, it's not
- a bug.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-